package terminal

import (
	"device-admin/internal/app/grpc/protoc/devicec"
	"device-admin/internal/app/grpc/service/pubsub"
	"encoding/base64"

	"192.168.1.75/go-pkg/errorx"
	"192.168.1.75/go-pkg/helper"
	"google.golang.org/protobuf/proto"
)

// PlayTTS 播放tts
func PlayTTS(robotID, text string) error {
	if robotID == "" {
		return errorx.New("设备id不能为空", -1)
	}
	if text == "" {
		return errorx.New("播放文本不能为空", -1)
	}
	playTTSReq := &devicec.PlayTTSReq{}
	playTTSReq.Text = text
	// 98语音播报
	sendMsg := &devicec.Msg{}
	sendMsg.Ack = 0
	sendMsg.Seq = helper.RandString(16)
	sendMsg.Name = string(playTTSReq.ProtoReflect().Descriptor().FullName())
	sendMsg.Content, _ = proto.Marshal(playTTSReq)
	// protobuf序列化
	bytes, _ := proto.Marshal(sendMsg)
	pubsub.CMDPublish(robotID, "97", "msg", base64.StdEncoding.EncodeToString(bytes))
	return nil
}
